local lingnue = fk.CreateSkill{
    name = "ym1__lingnue",
}
Fk:loadTranslationTable{
    ["ym1__lingnue"] = "凌虐",
    [":ym1__lingnue"] = "出牌阶段每项各限一次，你可以弃置一张牌或失去1点体力，然后展示并获得一名角色的一张牌。若此牌为装备牌或伤害牌，你可以使用之。",
    ["#ym1__lingnue"] = "凌虐：弃置一张牌，或不选牌失去1点体力，展示并获得一名角色的一张牌",
    ["#ym1__lingnue-card"] = "凌虐：展示并获得 %dest 的一张牌",
    ["#ym1__lingnue-use"] = "凌虐：你可以使用这些牌",

    ["$ym1__lingnue1"] = "以杀立威，谁敢反我？",
    ["$ym1__lingnue2"] = "将这些乱臣贼子，尽皆诛之！",
}

lingnue:addEffect("active", {
    anim_type = "control",
    prompt = "#ym1__lingnue",
    max_card_num = 1,
    target_num = 1,
    can_use = function (self, player)
        return #player:getTableMark("ym1__lingnue-phase") < 2
    end,
    card_filter = function (self, player, to_select, selected, selected_targets)
        return #selected == 0 and not player:prohibitDiscard(to_select)
    end,
    target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
        return #selected == 0 and not to_select:isNude()
    end,
    feasible = function (self, player, selected, selected_cards, card)
        local mark = player:getTableMark("ym1__lingnue-phase")
        if #selected == 1 then
            if not table.contains(mark, "loseHp") and #selected_cards == 0 then
                return true
            end
            if not table.contains(mark, "discard") and #selected_cards == 1 then
                return true
            end
        end
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        if #effect.cards > 0 then
            room:addTableMark(player, "ym1__lingnue-phase", "discard")
            room:throwCard(effect.cards, lingnue.name, player)
        else
            room:addTableMark(player, "ym1__lingnue-phase", "loseHp")
            room:loseHp(player, 1, lingnue.name)
        end
        local card = room:askToChooseCard(player, {
            target = target,
            flag = "he",
            skill_name = lingnue.name,
            prompt = "#ym1__lingnue-card::"..target.id,
        })
        if card then
            local show = Fk:getCardById(card)
            room:showCards(show, target)
            room:obtainCard(player, show, true, fk.ReasonPrey, player, lingnue.name)
            if show.type == Card.TypeEquip or show.is_damage_card then
                room:askToUseRealCard(player, {
                    pattern = {card},
                    skill_name = lingnue.name,
                    prompt = "#ym1__lingnue-use",
                    extra_data = {
                        bypass_times = true,
                        extraUse = true,
                    }
                })
            end
        end
    end,
})

return lingnue